package com.luobo.shiro.controller;


import com.luobo.shiro.bean.Result;
import com.luobo.shiro.domain.entity.User;
import com.luobo.shiro.service.IUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService iUserService;

    /**
     * 用户查询
     */
    @GetMapping("/userList")
    @RequiresPermissions("user:view")//权限管理;
    public Result listUsers() {
        List<User> users = iUserService.listUsers();
        return Result.success(users);
    }

    /**
     * 用户添加
     */
    @PostMapping("/userAdd")
    @RequiresPermissions("user:add")//权限管理;
    public Result userInfoAdd(User user) {
        Integer insert = iUserService.insert(user);
        if (insert > 0) {
            return Result.success();
        }
        return Result.error();

    }

    /**
     * 用户删除
     */
    @DeleteMapping("/userDel")
    @RequiresPermissions("user:del")//权限管理;
    public String userDel() {
        return "userDel";
    }

}
